﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;

namespace IHISCETeim.Web.MachineSys.MarketModel
{
    public partial class MSellDetailReport : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "MSellDetailReport";
            }
        }
        protected DateTime BuyDateFrom
        {
            get
            {
                return GetRequestValue<DateTime>("BuyDateFrom", new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1));
            }
        }
        protected DateTime BuyDateTo
        {
            get
            {
                return GetRequestValue<DateTime>("BuyDateTo", DateTime.Now);
            }
        }

        protected string ItemName
        {
            get
            {
                return GetRequestValue<string>("ItemName", "");
            }
        }

        protected override string orderField
        {
            get
            {
                return base.orderField.IsEmptyOrNull() ? "ItemName" : base.orderField;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
        }
        protected DataTable SUMDT = null;
        protected void DataBind()
        {
            //  string wheresql = QueryOperatorsEnumHelper.ConvertCommonOperator(CommonFiled, QueryOperatorsEnum.包含, CommonValue);
            DataTableCollection DTC = MMarketItemController.MSellDetail_GetPagination(GetSQLWhere(), pageNum, 99999999, SQLSort, ref TotalCount);
            this.rpMenu.DataSource = DTC[0];
            this.rpMenu.DataBind();

            SUMDT = DTC[1];
        }

        protected string GetSQLWhere()
        {

            string wheresql = "";
            string sqlcommonFiled = "";
            sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("SellDate", QueryOperatorsEnum.范围, BuyDateFrom.ToString("yyyy-MM-dd 00:00:00") + "|" + BuyDateTo.ToString("yyyy-MM-dd 23:59:59:59"));
            wheresql = sqlcommonFiled;
            string ItemNameSql = "";
            if (!string.IsNullOrEmpty(ItemName))
            {
                ItemNameSql = QueryOperatorsEnumHelper.ConvertCommonOperator("AgentName", QueryOperatorsEnum.包含, ItemName);
                if (sqlcommonFiled == "")
                    wheresql = ItemNameSql;
                else
                    wheresql = wheresql + " and " + ItemNameSql;
            }
            return wheresql;
        }
    }
}